import request from '@/utils/request'

const baseUri = '/role'


const roleService = {
  //修改角色的权限
  updateRolePermission: (updateRolePermissionDto) => {
    return request({
      url: `${baseUri}/updateRolePermission`,
      method: 'post',
      data: updateRolePermissionDto
    })
  },

  list: (searchMap) => {
    return request({
      url: `${baseUri}/list`,
      method: 'post',
      data:searchMap
    })
  },

  find: (id) => {
    return request({
      url: `${baseUri}/find`,
      method: 'get',
      params: { id }
    })
  },

  findAll: () => {
    return request({
      url: `${baseUri}/findAll`,
      method: 'get'
    })
  },

  update(id,role) {

    //判断是否有ID，没有就是新增
    if(id===null || id===''){
      return this.add(role)
    }
    return request({
      url: `${baseUri}/update`,
      method: 'post',
      data: role // 将部门对象作为请求体传递
    });
  },
  
  add(role) {
    return request({
      url: `${baseUri}/add`,
      method: 'post',
      data: role
    });
  },

  remove: (id) => {
    return request({
      url: `${baseUri}/delete`,
      method: 'get',
      params: { id }
    })
  },

  batchRemove: (batchDeleteDto) => {
    return request({
      url: `${baseUri}/batchRemove`,
      method: 'post',
      data: batchDeleteDto
    })
  },
}

export default roleService